@svizzle/utils/string-[array-number]

Methods

(static) arrayMaxBy(key) → {function}

Source:
Since:
  • 0.1.0
See:

Return a function expecting an array of objects and returning the max of values by the provided key. The same can be done by arrayMaxWith(_.getKey(key)) but here we avoid invoking a function for all the items.

Example
> maxByA = arrayMaxBy('a')
> maxByA([{a: -1, b: -1}, {a: 0, b: 0}])
0
> maxByA([{a: 1, b: 1}, {a: 2, b: -2}])
2
Parameters:
Name Type Description
key string
Returns:
  • Array -> Number
Type
function

(static) arrayMinBy(key) → {function}

Source:
Since:
  • 0.1.0
See:

Return a function expecting an array of objects and returning the min of values by the provided key The same can be done by arrayMinWith(_.getKey(key)) but here we avoid invoking a function for all the items.

Example
> minByA = arrayMinBy('a')
> minByA([{a: -1, b: -1}, {a: 0, b: 0}])
-1
> minByA([{a: 1, b: 1}, {a: 2, b: -2}])
1
Parameters:
Name Type Description
key string
Returns:
  • Array -> Number
Type
function